package net.controller;

import net.bo.KUtilisateur;
import net.ko.framework.KoSession;
import net.ko.validation.KValidator;

public class KValidateForgetPassword extends KValidator {

	public void validateMail() {
		String mail = getValue("mail");
		KUtilisateur user = KoSession.kloadOne(KUtilisateur.class, "mail='" + mail + "'");

		if (user.isLoaded()) {
			onValid(mail);
		} else {
			setOnError(true);
		}

	}

	@Override
	protected void onError(String fieldName) {
		if ("mail".equals(fieldName))
			displayError("Aucune adresse ne correspond");

		addJSContent("show($('errors'),true);");

	}

	@Override
	protected void onValid(String fieldName) {
		addJSContent("show($('errors'),false);");
	}

}
